package com.ruget.ools.log.starter.event;

import java.util.function.Consumer;

import com.ruget.ools.log.starter.entity.OptLogDTO;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.core.annotation.Order;
import org.springframework.scheduling.annotation.Async;

/**
 * description 异步监听日志事件
 * create Time at 2022/9/1 9:37
 *
 * @author alice.ruge
 * @since 0.0.7
 */
@Slf4j
@AllArgsConstructor
public class SysLogListener {
    private Consumer<OptLogDTO> consumer;

    @Async
    @Order
    @EventListener(SysLogEvent.class)
    public void saveSysLog(SysLogEvent event) {
        OptLogDTO optLog = (OptLogDTO) event.getSource();
        consumer.accept(optLog);
    }
}
